#!/usr/bin/env python

import nltk


def gender_features(word):
	return {'last_letter':word[-1]}

# prepare data
from nltk.corpus import names
labeled_name = [(name,'male') for name in names.words('male.txt')] +\
	[(name,'female') for name in names.words('female.txt')]

import random
random.shuffle(labeled_name)

featuresets = [(gender_features(n),gender) for (n,gender) in labeled_name]
print featuresets[0]
train_set = featuresets[1500:]
test_set = featuresets[:1500]

classifier = nltk.NaiveBayesClassifier.train(train_set)
print nltk.classify.accuracy(classifier,test_set)
classifier.show_most_informative_features(5)
print classifier.classify(gender_features('Neo'))
print classifier.classify(gender_features('Trinity'))
